package org.inspiration.dudu.web.controller.user;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.inspiration.dudu.common.pojo.Result;
import org.inspiration.dudu.user.model.dto.UserLikeDTO;
import org.inspiration.dudu.web.annotation.Loggable;
import org.inspiration.dudu.web.service.user.UserLikeFacadeService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user-like")
@Tag(name = "用户点赞接口")
@RequiredArgsConstructor
@Loggable
public class UserLikeController {

    private final UserLikeFacadeService userLikeFacadeService;

    @PostMapping
    @Operation(summary = "用户点赞")
    public Result<Void> createUserLike(@RequestBody UserLikeDTO userLikeDTO) {
        userLikeFacadeService.createUserLike(userLikeDTO);
        return Result.success();
    }

    @DeleteMapping
    @Operation(summary = "用户取消点赞")
    public Result<Void> deleteUserLike(@RequestBody UserLikeDTO userLikeDTO) {
        userLikeFacadeService.deleteUserLike(userLikeDTO);
        return Result.success();
    }

    @GetMapping("/is-liked")
    @Operation(summary = "检查用户是否已点赞")
    public Result<Boolean> isLiked(@RequestParam("userId") Long userId,
                                   @RequestParam("contentId") String contentId) {
        Boolean isLiked = userLikeFacadeService.isLiked(userId, contentId);
        return Result.success(isLiked);
    }


    @PutMapping("/mark-as-read")
    @Operation(summary = "标记点赞为已读")
    public Result<Void> markAsRead(@RequestBody UserLikeDTO userLikeDTO) {
        userLikeFacadeService.markAsRead(userLikeDTO);
        return Result.success();
    }

    @GetMapping("/contents")
    @Operation(summary = "获取用户最近的点赞内容")
    public Result<List<Map<String, Object>>> getLikeContentsByUserIdOrderByDESC(@RequestParam("userId") Long userId,
                                                                                @RequestParam("pageNum") Integer pageNum,
                                                                                @RequestParam("pageSize") Integer pageSize) {
        List<Map<String, Object>> list = userLikeFacadeService.getLikeContentsByUserIdOrderByDESC(userId, pageNum, pageSize);
        return Result.success(list);
    }

    @GetMapping("/receive")
    @Operation(summary = "获取用户最近收到的点赞")
    public Result<List<Map<String, Object>>> getReceiveLikeContentsByUserIdOrderByDESC(
            @RequestParam("userId") Long userId,
            @RequestParam("pageNum") Integer pageNum,
            @RequestParam("pageSize") Integer pageSize
    ) {
        List<Map<String, Object>> res = userLikeFacadeService.getReceiveLikeContentsByUserIdOrderByDESC(userId, pageNum, pageSize);
        return Result.success(res);
    }


}
